package week2;

import org.junit.Test;

import java.util.Scanner;

public class Day1 {
    int id;
    String name;
    int age1;

    @Override
    public String toString() {
        return "Day1{" +       //返回一个字符串，调用这个方法，得到return返回值的量
                "id=" + id +
                ", name='" + name + '\'' +
                ", age1=" + age1 +
                '}';
    }

    public  void main() {
        System.out.println("序号是" + id + "的" + name + "年龄是" + age1 + "正在消费");
    }

    @Test
    public void t1(){
        Day1 student = new Day1();
        student.id = 4;
        student.name = "是理性";
        student.age1 = 18;
        student.main();
    }
//输入1 按id,输入2按照name,输入3，按照age1
    @Test
    public void t8(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入数字，显示几个人");
        int count = scanner.nextInt();
        Day1[] students = new Day1[count];
        for (int i = 0 ;i < count; i++){
            Day1 student = new Day1();    //设student对象
            student .id = scanner.nextInt();
            student.name = scanner.next();
            student.age1 = scanner.nextInt();
            students[i] = student;    //将students数组中每个位置都是类Student类型的，将对象中的属性值代入数组中
        }

       for (int j = 0; j < count; j++){
           Day1 student = students[j];   //遍历数组，每一个对象就是数组中的一值
           System.out.println(student);
       }

       while (true) {
           System.out.println("请输入1/2/3/0来搜索学生");
           int num = scanner.nextInt();
           boolean bool = false;
           if (num == 0){         //卫操作
               break;
           }

           switch (num) {
               case 1:
                   System.out.println("请输入id");
                   int id1 = scanner.nextInt();
                   for (int k = 0; k < count; k++) {
                       Day1 student = students[k];   //方法中定义的变量初始化，赋值为
                       if (id1 == students[k].id) {
                           System.out.println(student.toString());
                           bool = true;
                       }
                   }
                   if(bool == false){
                       System.out.println("查无此人");
                   }
                   break;
               case 2:
                   System.out.println("请输入name");
                   String str = scanner.nextLine();
                   for (int m = 0; m < count; m++) {
                       if (str.equals(students[m].name)) {
                           System.out.println(str);
                           System.out.println(students[m].toString());
                       }
                   }
                   break;
               case 3:
                   System.out.println("请输入age");
                   int ag1 = scanner.nextInt();
                   for (int n = 0; n < count; n++) {
                       if (ag1 == students[n].age1) {
                           System.out.println(ag1);
                           System.out.println(students[n].toString());
                       }
                   }
                   break;
           }

       }


    }

    @Test
    public void t9(){
        PersonStudent personStudent = new PersonStudent(1,"dfhskjal",17,"nan","sdjkf");
        System.out.println(personStudent.toString());
    }


}
